<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
        <meta charset="utf-8"/>
        <meta name="format-detection" content="telephone=no"/>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <title>图书详情预览</title>
		 <link rel="stylesheet" href="http://apps.bdimg.com/libs/frozenui/1.3.0/css/frozen.css">
    	<link href="http://cdn.bootcss.com/Swiper/3.3.1/css/swiper.min.css" rel="stylesheet">
    	<script src="http://cdn.bootcss.com/Swiper/3.3.1/js/swiper.min.js"></script>
        <link rel="stylesheet" href="comm/w-src.css">
    	<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>   
</head>
<body>
<div class="mainIndex" style="overflow-x:hidden;">
      <!--轮播图-->
      <div class="swiper-container">
          <div class="swiper-wrapper">  
          </div>
          <div class="swiper-pagination"></div>
      </div>
      <div class="onePic">
      </div>
    <!--轮播图-->
      <section>
          <div class="lay">
            <div class="bookName"></div>
            <div class="bookeasyintro"></div>
            <div class="pricelist">
                <div class="newPrice left"></div>
                <div class="right discountDiv">
                  <span class="oldPrice">
                    <del></del>
                  </span>
                  <span class="discount">
                  </span>
                </div>
                <div class="clear"></div>
            </div>
            <div class="booklist">
                 <div class="left bookIntro">库存</div>
                 <div class="stock left"></div>
                 <div class="clear"></div>
            </div>
            <div class="booklist">
                 <div class="left bookIntro">作者</div>
                 <div class="bookauthor left"></div>
                 <div class="clear"></div>
            </div>
            <div class="booklist ">
                <div class="left bookIntro">出版社</div>
                <div class="bookpress left"></div>
                <div class="clear"></div>
            </div>
            <div class="bookIntrolist">
	           	<span class="bookIntro">图书简介</span>
            	<iframe id="bookDetailFrame"  scrolling="no" frameborder="0" marginheight="0" marginwidth="0" style="height:0px;"></iframe>
            </div> 
          </div>
          <div class="comention">
			<div class="comline bookIntro" id="comline"></div>
			<ul id="items" style="margin:0 10px;"></ul>
		 </div>
      </section>
</div>
  
<!--full img-->
<div class="fullScreenDiv" onclick="cancelFull()">
   <!--轮播图-->
      <div class="swiper-container" >
          <div class="swiper-wrapper">  
          </div>
          <div class="swiper-pagination"></div>
      </div>
</div>
<!--full img-->

<script>
var loop = true;
var d = null;
function getBookId(){

    var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
    args = {},
    items = qs.length ? qs.split("&") : [],
    item = null,
    name = null,
    value = null,
    i = 0,
    len = items.length;
    for (i = 0; i < len; i++) {
        item = items[i].split("=");
        name = decodeURIComponent(item[0]);
        value = decodeURIComponent(item[1]);
        if (name.length) {
            args[name] = value
        }
    }
    return args;
}

$(function() {
	var bookId = getBookId().bookId;
	var storeId = getBookId().storeId;
	var urlinfo = window.location.href; 
	var i = urlinfo.indexOf('res');
	var p = urlinfo.substring(0,i);
	var url = null;
	if(storeId != null){
		url = p+ "/book/bookinfo/viewBook?bookId="+bookId+"&storeId="+storeId;
	}else{
		url = p+ "/book/bookinfo/viewBook?bookId="+bookId;
	}
	

 	$.ajax({
 		url : url,
 		async:false,
 		success : function(data){
 			d  = data;
 			var silderHtml = "";
 			if (data.corouselImg.length == 0) {
 		        data.corouselImg.push("http://www.wassk.cn/Myftp/upload/jlsj/file/noPic.jpg");
 		        loop = false
 		    }
 			for (var i = 0; i < data.corouselImg.length; i++) {
 		        silderHtml += '<div class="swiper-slide" onclick="fullScreen(' + i + ')"><img src="' + data.corouselImg[i] + '" class="img' + i + '"  onerror="errImg(' + i + ')"/></div>'
 		    }
 		    $(".mainIndex>.swiper-container .swiper-wrapper").append(silderHtml);
 		    $(".mainIndex>.swiper-container").css("height", $(".mainIndex .swiper-container").width());

			if (data.corouselImg.length != 1) {
				var swiper = new Swiper(".mainIndex>.swiper-container",
				{
					pagination : ".mainIndex>.swiper-container .swiper-pagination ",
					paginationClickable : true,
					loop : loop,
				});
			}
			if (data.bookDetail != undefined) {
				var first = data.bookDetail.indexOf("<script");
				var firstContent = data.bookDetail.substring(first + 9);
				var second = firstContent.indexOf('script>');
				var fristHtml = data.bookDetail.substring(0, first);
				var secondHmtl = firstContent.substring(second + 8);
				data.bookDetail = fristHtml + secondHmtl;
				$("#bookDetailFrame").contents().find("body").append(data.bookDetail);
			}
			var bookdetailArr = new Array();
			if (data.introduction == undefined) {
				data.introduction = "";
			}
			if (data.relatedBook == undefined) {
				data.relatedBook = [];
			}
			var relateBookNull = 0, silderbottomHtml = "";
		    for(var i = 0; i < data.relatedBook.length; i ++){
		    	 if(data.relatedBook[i].bookName == ""){
		    		relateBookNull +=1;
		    	 }
		    	 if(data.relatedBook[i].price == ""){
		    		 relateBookNull +=1;
				 }
		    	 if(data.relatedBook[i].url == ""){
		    		 relateBookNull +=1; 
		    		 relateBookNull = 3;
				 }
		    	 if(relateBookNull != 3){
		    		 if(data.relatedBook[i].src ==""){
		    			 data.relatedBook[i].src = "http://www.wassk.cn/Myftp/upload/jlsj/file/noPic.jpg";
		    		 }
		    		 var num = new Number(data.relatedBook[i].price);
		    		 num = num.toFixed(2);
		    		 silderbottomHtml += '<div class="swiper-slide swiper-slide-new" >'+
		    		 							'<a href="'+ data.relatedBook[i].url +'" target="_blank">'+
		    		 								'<div class="bookintroImg">'+
		    			 				 				'<img src="' + data.relatedBook[i].src + '" class=" bookIntroImg'+i+'" onerror="errorBookDetailImg('+i+')"/>'+
		    			 				 			'</div>'+
		    			 				 			'<div class="bookDetailtext detailbookName">'+data.relatedBook[i].bookName+'</div>'+
		    			 				 			'<div class="bookDetailtext detailprice">￥'+num+'</div>'+
		    			 				 		'</a>'+
		    			 				 '</div>';
		    	 } 
		    	 relateBookNull=0;
		    }
		    
			if (silderbottomHtml == "") {
					$(".bookIntroDetailist").css("display", "none");
			}
			$(".mainIndex #bookDetail .swiper-container .swiper-wrapper").append(silderbottomHtml);
			var swiper2 = new Swiper(".mainIndex #bookDetail .swiper-container", {
						nextButton : '.swiper-button-next',
						prevButton : '.swiper-button-prev',
						slidesPerView : 3,
						spaceBetween : 10
			});
			$('.arrow-left').on('click', function(e) {
				e.preventDefault()
				mySwiper.swipePrev()
			})
			$('.arrow-right').on('click', function(e) {
				e.preventDefault()
				mySwiper.swipeNext()
			})

			if (data.discount == 100) {
				$(".discountDiv").css("display", "none");
			}
			
			data.discount = getBookId().goodsDiscount; 
			
			$(".bookName").text(data.bookName);
			$(".bookeasyintro").text(data.bookeasyintro);
		    if (data.discount != "100") {
		        $(".oldPrice del").text("￥" + data.oldPrice);
		        $(".discount").text(data.discount / 10 + "折")
		        $(".discountDiv").css("display","block"); 
		    }
		    $(".newPrice").text("￥" + (data.oldPrice * data.discount / 100).toFixed(2));
		    if(storeId != 'undefined'){
		    	$(".stock").css("display","block"); 
		    	$(".stock").text(data.stock);
		    }else{
		    	$(".stock").css("display","none"); 
		    }
		   
			$(".bookauthor").text(data.author);
			$(".bookpress").text(data.press);
			
			var zhtml = '';
			if (data.rCount == '' || data.rCount == undefined) {
				zhtml += '<span>评论（共0条）</span>';
			} else {
				zhtml += '<span>评论（共' + data.rCount + '条)</span>';
			}
			$("#comline").html(zhtml);
			zhtml = '';
			if (data != undefined) {
				if (data.rCount == '' || data.rCount == undefined) {
					zhtml += '<li class="comment" style="text-align:center;height:50px">暂无评论</li>';
					$("#checkcom").css("display", "none");
					// $(".combtn span:last-child").css("margin-left","50%")
				} else {
					for (var i = 0; i < data.rList.length; i++) {
						var nickname = "";
						if (/^0?1[3|4|5|8][0-9]\d{8}$/g.test(data.rList[i].nickName)) {
							nickname = data.rList[i].nickName.substr(0, 3) + '****'+ data.rList[i].nickName.substr(7);
						} else {
							nickname = data.rList[i].nickName;
						}
						zhtml += '<li class="comment">';
						zhtml += '<div class="left com-content">';
						zhtml += '<p>' + data.rList[i].reviews + '<p>';
						zhtml += '<p>' + data.rList[i].createTime.substr(0, 10)
								+ '</p>';
						zhtml += '</div>';
						zhtml += '<div class="right com-img">';
						if (data.rList[i].headLogo != ""&& data.rList[i].headLogo != undefined) {
							zhtml += '<img src="'; 
				 			zhtml+=data.rList[i].headLogo;
					 		zhtml+='"/>';
						} else {
							zhtml += '<img src="../../images/noUserPic.png" />';
						}
						//zhtml+='<p>'+data.rList[i].nickName+'</p>';
						zhtml += '<p>' + nickname + '</p>';
						zhtml += '</div>';
						zhtml += '</li>';
					}
				}
			}
			$("#items").html(zhtml);
		}
	});
});
var acWidth = new Array();
var acHeight = new Array();
var boWidth = new Array();
var boHeight = new Array();
window.onload = function() {
	if (!loop) {
		$(".img0").css("margin-top",
				($(".mainIndex .swiper-container").width() - 203) / 2
						+ "px")
	} else {
		for (var i = 0; i < d.corouselImg.length; i++) {
			acWidth[i] = $(".img" + i).width();
			acHeight[i] = $(".img" + i).height();
			if (acWidth[i] > acHeight[i]) {
				$(".img" + i).attr("width",
						$(".mainIndex .swiper-container").width() + "px");
				$(".img" + i).css(
						"margin-top",
						($(".mainIndex .swiper-container").width() - $(
								".img" + i).height())
								/ 2 + "px")
			} else {
				$(".img" + i).attr("height",
						$(".mainIndex .swiper-container").width() + "px")
			}
		}

	}
	for (var i = 0; i < d.relatedBook.length; i++) {
		boWidth[i] = Math.abs($(".bookIntroImg" + i).width()
				- $(".bookintroImg").width());
		boHeight[i] = Math.abs($(".bookIntroImg" + i).height()
				- $(".bookintroImg").height());
		if (acWidth[i] > acHeight[i]) {
			$(".bookIntroImg" + i).attr("height",
					$(".bookintroImg").height() + "px");
			$(".bookIntroImg" + i).css(
					"margin-left",
					($(".bookintroImg").width() - $(".bookIntroImg" + i)
							.width())
							/ 2 + "px")
		} else {
			$(".bookIntroImg" + i).attr("width",
					$(".bookintroImg").width() + "px");
			$(".bookIntroImg" + i).css(
					"margin-top",
					($(".bookintroImg").height() - $(".bookIntroImg" + i)
							.height())
							/ 2 + "px")
		}
	}
	var ifm = document.getElementById("bookDetailFrame");
	var subWeb = document.frames ? document.frames["bookDetailFrame"].document
			: ifm.contentDocument;
	if (ifm != null && subWeb != null) {
		$("#bookDetailFrame").css("height", subWeb.body.scrollHeight);
		ifm.height = subWeb.body.scrollHeight;
		ifm.width = subWeb.body.scrollWidth;
	}
};
window.onresize = function() {
	$(".mainIndex .swiper-container").css("height",
			$(".swiper-container").width() + "px");
	window.onload()
};
function fullScreen(index) {
	$(".mainIndex").css("display", "none");
	$(".fullScreenDiv").css("display", "block");
	$(".fullScreenDiv .swiper-wrapper").children().remove();
	var silderfullHtml = "";
	for (var i = 0; i < d.corouselImg.length; i++) {
		silderfullHtml += '<div class="swiper-slide" onclick="cancelFull()"><img src="'
				+ d.corouselImg[i]+ '" class="fullImg'+ i+ '"  onerror="errorfullImg('+ i+ ')"/>'
				+ '<div class="pagePos">'+ '<span class="nowpage">'+ (i + 1)
				+ "&nbsp;</span>&frasl;"+ '<span class="totalpage">&nbsp;'+ d.corouselImg.length + "</span>" + "</div>" + "</div>"
	}
	$(".fullScreenDiv .swiper-wrapper").append(silderfullHtml);
	$(".fullScreenDiv .swiper-container").css("height",
			$(window).width() + "px");
	$(".fullScreenDiv").css(
			"margin-top",
			($(window).height() - $(".fullScreenDiv .swiper-container").height())/ 2 + "px");
	if (d.corouselImg.length != 1) {
		var swiper = new Swiper(".fullScreenDiv .swiper-container", {
			loop : loop,
			initialSlide : index,
		});
	}

	if (!loop) {
		$(".fullImg0").css(
				"margin-top",
				($(".fullScreenDiv .swiper-container").width() - 203) / 2
						+ "px")
	} else {
		for (var i = 0; i < d.corouselImg.length; i++) {
			if (acWidth[i] > acHeight[i]) {
				$(".fullImg" + i).attr(
						"width",
						$(".fullScreenDiv .swiper-container").width()
								+ "px");
				$(".fullImg" + i).css(
						"margin-top",
						($(".fullScreenDiv .swiper-container").width() - $(
								".fullImg" + i).height())
								/ 2 + "px")
			} else {
				$(".fullImg" + i).attr(
						"height",
						$(".fullScreenDiv .swiper-container").width()
								+ "px")
			}
		}
	}
}
function cancelFull() {
	$(".mainIndex").css("display", "block");
	$(".fullScreenDiv").css("display", "none")
}
function errImg(index) {
	$(".img" + index).css("margin-top",
			(($(window).width() - 11) / 2 + "px"))
}
function errorfullImg(index) {
	$(".fullImg" + index).css("margin-top",
			(($(window).width() - 11) / 2 + "px"))
};
function errorBookDetailImg(index) {
	$(".bookIntroImg" + index).attr("src",
			"http://www.wassk.cn/Myftp/upload/jlsj/file/noPic.jpg");
}


</script>
</body>
</html>
